import { createApp } from "vue";
import App from "./App.vue";
import router from "./router/index.js";
// 动态路由
import { addDynamicRoutes } from "@/router";
// vuex 
import { createPinia } from "pinia";
// ElementPlus
import ElementPlus from "element-plus";
import "element-plus/dist/index.css";
import axios from 'axios'
import * as ElementPlusIconsVue from "@element-plus/icons-vue";

import * as echarts from "echarts"; // npm install echarts --save 

// 全局样式
import "./styles/index.scss";
// rem
import 'amfe-flexible'
// 时间戳
import dayjs from "dayjs";
// 解析
import parse from "./utils/parse";
// input
import input from './utils/input'
// 自定义指令
import { setupPermission } from "@/directives";
import { btnPreventReClick } from "@/preventReClick";
// axios
import http from "./store/http.js";
import httpx from "./store/httpx.js";
import { post , get } from './store/http.js'
// vant
import { Button,CountDown  } from 'vant';
// 图片 全局
import uploadImg from "@/components/uploadImg.vue";
// element 中文
import locale from "element-plus/es/locale/lang/zh-cn";
// 字典
import dictionary from "./store/dictionary.js";
// 全局方法
import filter from "@/utils/filter";
// 处理element-ui内联样式px2rem,全局挂载
function px2rem(px) {
  if (/%/gi.test(px)) {
    // 有百分号%，特殊处理，表述pc是一个有百分号的数，比如：90%
    return px; 
  } else {
    return parseFloat(px) / 192 + 'rem';
  }
}

const app = createApp(App);
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component);
}
app.config.globalProperties.$http = http;
app.config.globalProperties.$httpx = httpx;
app.config.globalProperties.$axios = axios;
app.config.globalProperties.$post = post;
app.config.globalProperties.$get = get;
app.config.globalProperties.$dayjs = dayjs;
app.config.globalProperties.$px2rem = px2rem;
app.config.globalProperties.$store = dictionary;
app.config.globalProperties.$filter = filter;
app.config.globalProperties.$parse = parse;
app.config.globalProperties.$input = input;
app.config.globalProperties.$echarts = echarts;

setupPermission(app);
btnPreventReClick(app);
app.component("uploadImg", uploadImg);
app.use(createPinia());
const storedRoutesStr = localStorage.getItem("dynamicRoutes");
if (storedRoutesStr) {
  const storedRoutes = JSON.parse(storedRoutesStr);
  addDynamicRoutes(storedRoutes);
}
app.use(router);
app.use(ElementPlus, { locale });
app.use(CountDown);
app.mount("#app");
